{% extends 'stocks/base.html' %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{% url 'strategy_dashboard' %}">策略仪表板</a></li>
                    <li class="breadcrumb-item active">策略列表</li>
                </ol>
            </nav>
            <h2>交易策略列表</h2>
            <p class="text-muted">所有已配置的交易策略及其表现统计</p>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">策略列表</h5>
                </div>
                <div class="card-body">
                    {% if strategy_stats %}
                        <div class="table-responsive">
                            <table class="table table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th>策略名称</th>
                                        <th>策略类型</th>
                                        <th>状态</th>
                                        <th>30天信号数</th>
                                        <th>平均强度</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for item in strategy_stats %}
                                        <tr>
                                            <td>
                                                <strong>{{ item.strategy.name }}</strong>
                                                {% if item.strategy.description %}
                                                    <br><small class="text-muted">{{ item.strategy.description }}</small>
                                                {% endif %}
                                            </td>
                                            <td>
                                                <span class="badge bg-primary">{{ item.strategy.get_strategy_type_display }}</span>
                                            </td>
                                            <td>
                                                <span class="badge {% if item.strategy.is_active %}bg-success{% else %}bg-secondary{% endif %}">
                                                    {% if item.strategy.is_active %}启用{% else %}禁用{% endif %}
                                                </span>
                                            </td>
                                            <td>
                                                {% if item.stats.error %}
                                                    <span class="text-muted">N/A</span>
                                                {% else %}
                                                    <span class="{% if item.stats.total_signals > 0 %}text-primary fw-bold{% else %}text-muted{% endif %}">
                                                        {{ item.stats.total_signals }}
                                                    </span>
                                                {% endif %}
                                            </td>
                                            <td>
                                                {% if item.stats.error %}
                                                    <span class="text-muted">N/A</span>
                                                {% else %}
                                                    <span class="badge {% if item.stats.avg_strength >= 70 %}bg-danger{% elif item.stats.avg_strength >= 50 %}bg-warning{% else %}bg-info{% endif %}">
                                                        {{ item.stats.avg_strength|floatformat:1 }}
                                                    </span>
                                                {% endif %}
                                            </td>
                                            <td>{{ item.strategy.created_at|date:"Y-m-d" }}</td>
                                            <td>
                                                <div class="btn-group btn-group-sm">
                                                    <a href="{% url 'strategy_detail' item.strategy.id %}" class="btn btn-outline-primary">
                                                        <i class="fas fa-eye"></i> 详情
                                                    </a>
                                                    <a href="{% url 'buy_signals' %}?strategy={{ item.strategy.id }}" class="btn btn-outline-info">
                                                        <i class="fas fa-search"></i> 信号
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <div class="alert alert-info">
                            <i class="fas fa-info-circle"></i> 暂无交易策略配置。
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <div class="row mt-4">
        <div class="col-12">
            <div class="d-flex gap-2">
                <a href="{% url 'strategy_dashboard' %}" class="btn btn-secondary">
                    <i class="fas fa-arrow-left"></i> 返回仪表板
                </a>
                <a href="{% url 'buy_signals' %}" class="btn btn-primary">
                    <i class="fas fa-list"></i> 查看所有买入信号
                </a>
            </div>
        </div>
    </div>
</div>
{% endblock %}
